<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>Choose a file</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<link rel="stylesheet" type="text/css" href="${path }/resources/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="${path }/resources/css/bootstrap-theme.css">
<script src="resources/js/jquery-3.1.1.js"></script>
<script src="${path }/resources/js/bootstrap.js"></script>

</head>

<body>
	<form action="upload/uploadLog" method="post"
		enctype="multipart/form-data">
		<input type="file" name="crashlog"></input>
		 <input type="submit" value="上传" />
	</form>	
	<div>
		<label>是否是首页</label><input type="checkbox" id="isFirst" checked="checked">
		<label>索引开始：</label><input type="text" id = "indexx"/>
		<label>搜索序列：</label><input type="text" id = "keyd"/>
	</div>
	<button id="get" onclick="getInfo()">获取</button>
	<div id="container"></div>
</body>
<script type="text/javascript">
	
	function upload()
	{
		var formData = new FormData();
		var name = $("input").val();
		formData.append("file",$("#upload")[0].files[0]);
		formData.append("name",name);
		$.ajax({ 
			url : Url,
			type : 'POST',
			data : formData,
			// 告诉jQuery不要去处理发送的数据
			processData : false, 
			// 告诉jQuery不要去设置Content-Type请求头
			contentType : false,
			beforeSend:function(){
				console.log("正在进行，请稍候");
			},
			success : function(responseStr) {
				if(responseStr.status===0){
					console.log("成功"+responseStr);
				}else{
					console.log("失败");
				}
			}, 
			error : function(responseStr) { 
				console.log("error");
			} 
		});
	}
	
	var	skip = 0; 

	function getInfo()
	{
		var keyword = $("#keyd").val();
		var startIndex = $("#indexx").val();
		var sIndex = parseInt(startIndex);
		if(!keyword)
		{
			alert("请输入索索序列");
			return;
		}
		var keyd = $("#keyd").val();
		var s1 = "http://service.picasso.adesk.com/v1/wallpaper/category/";
		var s2 = "/wallpaper?limit=30&skip=";
		var e = "&adult=true&first="+($("isFirst").attr('checked') ? 1 : 0)+"&order=new";
		var sb= $("#container").html();
		$.ajax({
			type:"GET",
			url:s1 + keyd + s2 + skip + e,
			cache:false,
			success: function(data)
			{
				var ds = data.res.wallpaper;				
				for(var i = 0;i<ds.length;i++)
				{
					var bean = ds[i];
					var tg = bean.tag;
					var desc = "";
					for(var j=0;j<tg.length;j++)
					{
						desc = desc + tg[j];
					}
					sb = sb + "insert into goods values("+(sIndex+i)+"," +"\'" +desc+"\'"+"," + 0.1 +","+"\'"+bean.img+"\'"+");<br/>"; 					
				}
				sIndex += ds.length;
				skip += ds.length;
				$("#indexx").val(sIndex);
				$("#container").html(sb);
            }
		});
	}
</script>
</html>
